﻿Imports Kimmo

Public Class clsFormDetails
    Private Shared BE As StringBuilder
    Private Shared Property TableID As Integer = 0
    Private Shared Property TableName As String = ""
    Private Shared Property TargetFolder As String = ""
    Private Shared Property ClassName As String = ""
    Private Shared Property TargetFile As String = ""
    Private Shared Property PrimaryKey As String = ""
    Private Shared Property ProjectName As String = ""
    Private Shared Property Title As String = ""

    Public Shared Function Build(ByVal iTableID As Integer) As String
        Dim clsPB As clsPropertyBuilder
        TableID = iTableID
        If TableID <= 0 Then
            Throw New Exception("Please specify the table id of the table to process first!")
            Exit Function
        End If
        ' get the path of the project
        TargetFolder = clsTables.ProjectPathByID(TableID.ToString)
        TableName = clsTables.TableNameByID(TableID.ToString)
        ProjectName = clsTables.ProjectNameByID(TableID.ToString)
        Title = TableName.Replace("_", " ")
        ClassName = TableName.Replace("_", "").Replace(" ", "")
        TargetFile = TargetFolder & "/frm" & ClassName & ".aspx"
        PrimaryKey = clsColumns.PrimaryKey(TableID)
        ' start processing
        ' process the header
        BE = New StringBuilder
        BE.Append("<%@ Page ")
        clsPB = New clsPropertyBuilder
        clsPB.AddProperty("Async", True)
        clsPB.AddProperty("Title", ProjectName & " > " & Title)
        clsPB.AddProperty("Language", "vb")
        clsPB.AddProperty("AutoEventWireup", "false")
        clsPB.AddProperty("CodeBehind", "frm" & ClassName & ".aspx.vb")
        clsPB.AddProperty("MaintainScrollPositionOnPostback", "true")
        clsPB.AddProperty("Inherits", ProjectName & ".frm" & ClassName)
        BE.Append(clsPB.Render)
        BE.AppendLine(" %>")

        ' another header section
        BE.Append("<!DOCTYPE html PUBLIC ")
        BE.Append(clsDL.QuoteString("-//W3C//DTD XHTML 1.1//EN"))
        BE.Append(" ")
        BE.Append(clsDL.QuoteString("http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"))
        BE.AppendLine(">")

        ' another header line
        clsPB = New clsPropertyBuilder
        BE.Append("<html ")
        clsPB.AddProperty("xmlns", "http://www.w3.org/1999/xhtml")
        clsPB.AddProperty("xmlns:v", "urn:schemas-microsoft-com:vml")
        BE.Append(clsPB.Render)
        BE.AppendLine(">")
        BE.AppendLine()

        ' another header line
        clsPB = New clsPropertyBuilder
        BE.Append("<head ")
        clsPB.AddProperty("head", "Head1")
        clsPB.AddProperty("runat", "server")
        BE.Append(clsPB.Render)
        BE.AppendLine(">")
        BE.Append("<title>" & ProjectName & " > " & Title)
        BE.AppendLine("</title>")

        ' add favicon
        clsPB = New clsPropertyBuilder
        BE.Append("<link ")
        clsPB.AddProperty("rel", "shortcut icon")
        clsPB.AddProperty("href", "favicon.ico")
        BE.Append(clsPB.Render)
        BE.AppendLine(" />")

        ' add css
        clsPB = New clsPropertyBuilder
        BE.Append("<link ")
        clsPB.AddProperty("href", "Styles/site.css")
        clsPB.AddProperty("rel", "stylesheet")
        clsPB.AddProperty("type", "text/css")
        BE.Append(clsPB.Render)
        BE.AppendLine(" />")

        ' add js
        clsPB = New clsPropertyBuilder
        BE.Append("<script ")
        clsPB.AddProperty("type", "text/javascript")
        clsPB.AddProperty("src", "Scripts/jquery-1.8.3.min.js")
        BE.Append(clsPB.Render)
        BE.Append("></script>")
        BE.AppendLine()

        ' add ms related
        BE.Append("<style type=")
        BE.Append(clsDL.QuoteString("text/css"))
        BE.AppendLine(">")
        BE.AppendLine("v\:* {behavior: url(#default#VML);}")
        BE.AppendLine("</style>")
        BE.AppendLine("</head>")
        BE.AppendLine()
        ' add the body
        BE.AppendLine("<body>")

        ' add relevant code
        clsPB = New clsPropertyBuilder
        clsPB.AddID("form1")
        clsPB.AddRunAtServer()
        BE.Append("<form ")
        BE.Append(clsPB.Render)
        BE.AppendLine(">")
        
        ' add page manager
        clsPB = New clsPropertyBuilder
        clsPB.AddID("PageManager1")
        clsPB.AddProperty("AutoSizePanelID", "RegionPanel1")
        clsPB.AddRunAtServer()
        BE.Append("<ext:PageManager ")
        BE.Append(clsPB.Render)
        BE.AppendLine("></ext:PageManager>")

        ' add comment window
        '<ext:Window ID="frmComment" BodyPadding="5" runat="server" Hidden="True" EnableBackgroundColor="True" EnableClose="False" 
        BE.Append("<ext:Window ")
        clsPB = New clsPropertyBuilder
        clsPB.AddID("frmComment")
        clsPB.AddProperty("BodyPadding", 5)
        clsPB.AddRunAtServer()
        clsPB.AddHidden("true")
        clsPB.AddEnableBackgroundColor("true")
        clsPB.AddProperty("EnableClose", "false")
        clsPB.AddProperty("EnableDrag", "false")
        clsPB.AddProperty("Height", "210px")
        clsPB.AddProperty("Icon", "Comment")
        clsPB.AddProperty("IsModal", "True")
        clsPB.AddProperty("Popup", "True")
        clsPB.AddProperty("Title", "Comment")
        clsPB.AddProperty("Width", "500px")
        BE.Append(clsPB.Render)
        BE.AppendLine(">")
        BE.AppendLine("<Items>")
        clsPB = New clsPropertyBuilder
        clsPB.AddID("tblComment")
        clsPB.AddRunAtServer()
        clsPB.AddPosition("Bottom")
        BE.Append("<ext:Toolbar ")
        BE.Append(clsPB.Render)
        BE.AppendLine(">")
        BE.AppendLine("<Items>")
        '<ext:ToolbarFill ID="ToolbarFill1" runat="server"></ext:ToolbarFill>
        BE.Append("<ext:ToolbarFill ")
        clsPB = New clsPropertyBuilder
        clsPB.AddID("ToolbarFill1")
        clsPB.AddRunAtServer()
        BE.Append(clsPB.Render)
        BE.AppendLine("></ext:ToolbarFill>")
        BE.AppendLine("</Items>")
        BE.AppendLine("</ext:Toolbar>")
        ' add textarea
        '<ext:TextArea runat="server" Height="150px" Width="485px" Label="Comment" ID="txtAddComment" 
        '        EmptyText="Add a comment" FocusOnPageLoad="True" Required="True" AutoGrowHeight="False" 
        '        RequiredMessage="Enter the comment here." ShowEmptyLabel="True" ShowRedStar="True"></ext:TextArea>
        clsPB = New clsPropertyBuilder
        BE.Append("<ext:TextArea ")
        clsPB.AddRunAtServer()
        clsPB.AddHeight("150")
        clsPB.AddWidth("485")
        clsPB.AddLabel("Comment")
        clsPB.AddID("txtAddComment")
        clsPB.AddEmptyText("Add a comment")
        clsPB.AddProperty("FocusOnPageLoad", "true")
        clsPB.AddRequired(True)
        clsPB.AddProperty("AutoGrowHeight", "false")
        clsPB.AddRequiredMessage("Enter the comment here.")
        clsPB.AddShowEmptyLabel(True)
        clsPB.AddShowRedStar(True)
        BE.Append(clsPB.Render)
        BE.AppendLine("></ext:TextArea>")
        BE.AppendLine("</Items>")
        BE.AppendLine("</ext:Window>")
        

        ' add region panel
        clsPB = New clsPropertyBuilder
        clsPB.AddID("RegionPanel1")
        clsPB.AddRunAtServer()
        clsPB.AddShowBorder("false")
        clsPB.AddEnableBackgroundColor("true")
        BE.AppendLine()
        BE.Append("<ext:RegionPanel ")
        BE.Append(clsPB.Render)
        BE.AppendLine(">")
        BE.AppendLine("<Regions>")
        BE.AppendLine()
        ' build the center region
        Build_CenterRegion(BE)
        BE.AppendLine()
        BE.AppendLine("</Regions>")
        BE.AppendLine("</ext:RegionPanel>")

        BE.AppendLine()
        BE.AppendLine("</body>")
        BE.AppendLine("</html>")


        ' ensure file is deleted first
        WebSite.File_Delete(TargetFile)
        WebSite.File_Update(TargetFile, BE.ToString)
        Return TargetFile
    End Function


    Public Shared Sub Build_CenterRegion(BE As StringBuilder)
        Dim clsPB As clsPropertyBuilder
        clsPB = New clsPropertyBuilder
        BE.Append("<ext:Region ")
        clsPB.AddID("reg" & ClassName & "Center")
        clsPB.AddSplit(True)
        clsPB.AddEnableSplitTip(True)
        clsPB.AddProperty("CollapseMode", "Mini")
        clsPB.AddShowBorder(True)
        clsPB.AddWidth("600")
        clsPB.AddProperty("Margins", "0 0 0 0")
        clsPB.AddShowHeader(True)
        clsPB.AddTitle("Projects")
        clsPB.AddIconURL("project")
        clsPB.AddEnableCollapse("false")
        clsPB.AddLayout("Fit")
        clsPB.AddAutoScroll(False)
        clsPB.AddPosition("Center")
        clsPB.AddRunAtServer()
        BE.Append(clsPB.Render)
        BE.AppendLine(">")
        BE.AppendLine("<Toolbars>")
        BE.Append("<ext:Toolbar ")
        clsPB = New clsPropertyBuilder
        clsPB.AddID("tbl" & ClassName & "Center")
        clsPB.AddRunAtServer()
        BE.Append(clsPB.Render)
        BE.AppendLine("></ext:Toolbar>")
        BE.AppendLine("</Toolbars>")
        BE.AppendLine("<Items>")
        ' add form details here
        Build_Form(BE)
        BE.AppendLine("</Items>")
        BE.AppendLine("</ext:Region>")
    End Sub

    Public Shared Sub Build_Form(BE As StringBuilder)
        Dim clsPB As clsPropertyBuilder
        clsPB = New clsPropertyBuilder
        BE.AppendLine()
        BE.Append("<ext:Form ")
        clsPB.AddID("frm" & ClassName)
        clsPB.AddShowHeader(False)
        clsPB.AddShowBorder(False)
        clsPB.AddProperty("LabelWidth", "100px")
        clsPB.AddRunAtServer()
        clsPB.AddProperty("AutoHeight", "true")
        clsPB.AddAutoScroll(True)
        clsPB.AddProperty("BodyPadding", "10px")
        clsPB.AddEnableBackgroundColor(True)
        BE.Append(clsPB.Render)
        BE.AppendLine(">")
        BE.AppendLine("<Rows>")
        ' add controls herein
        Build_FormControls(BE)
        BE.AppendLine("</Rows>")
        BE.AppendLine("</ext:Form>")
        BE.AppendLine()
    End Sub

    Public Shared Sub Build_FormControls(BE As StringBuilder)
        Dim clsPB As clsPropertyBuilder
        BE.AppendLine()

        ' column definitions based on columns defined in the columns table
        Dim xTable As DataTable = SQLCompact.OpenDataTable("select * From Columns Where TableID = " & TableID & " order by [Position];")
        For Each xRow As DataRow In xTable.Rows
            Dim sColumnName As String = xRow("ColumnName").ToString
            Dim sCaption As String = xRow("Caption").ToString
            Dim sEmptyText As String = xRow("EmptyText").ToString
            Dim sControlType As String = xRow("ControlType").ToString
            Dim sTextAlign As String = xRow("TextAlign").ToString
            Dim sIsRequired As String = xRow("IsRequired").ToString
            Dim sIsReadOnly As String = xRow("IsReadOnly").ToString
            Dim sToolTip As String = xRow("ToolTip").ToString
            Dim sIsAutoPostBack As String = xRow("IsAutoPostBack").ToString
            Dim sIsVisible As String = xRow("IsVisible").ToString
            Dim sDataFormat As String = xRow("DataFormat").ToString
            sDataFormat = sDataFormat.Replace("{0:", "").Replace("}", "")
            sDataFormat = sDataFormat.Replace("{0}", "")

            ' buildrowfirst
            clsPB = New clsPropertyBuilder
            clsPB.AddRunAtServer()
            clsPB.AddID("row" & sColumnName)
            BE.AppendLine()
            BE.Append("<ext:FormRow ")
            BE.Append(clsPB.Render)
            BE.AppendLine(">")
            BE.AppendLine("<Items>")
            
            Dim sLine As String = ""
            Select Case sControlType
                Case "Image"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:Image ")
                    clsPB.AddID("img" & sColumnName)
                    clsPB.AddRunAtServer()
                    clsPB.AddProperty("ImageAlt", sCaption)
                    clsPB.AddProperty("ImageHeight", "300px")
                    clsPB.AddProperty("ImageWidth", "300px")
                    clsPB.AddProperty("ImageUrl", "")
                    If sIsReadOnly = "Y" Then clsPB.AddProperty("ReadOnly", "true")
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    'If sIsRequired = "Y" Then
                    '    clsPB.AddShowRedStar(True)
                    '    clsPB.AddRequired(True)
                    '    clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    'End If
                    'If sIsAutoPostBack = "Y" Then
                    '    clsPB.AddProperty("OnCheckedChanged", "chk" & sColumnName & "_CheckedChanged")
                    '    clsPB.AddAutoPostBack(True)
                    'End If
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:Image>")
                Case "HyperLink"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:HyperLink ")
                    clsPB.AddID("link" & sColumnName)
                    clsPB.AddRunAtServer()
                    clsPB.AddProperty("NavigateUrl ", "")
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    'If sIsRequired = "Y" Then
                    '    clsPB.AddShowRedStar(True)
                    '    clsPB.AddRequired(True)
                    '    clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    'End If
                    'If sIsAutoPostBack = "Y" Then
                    '    clsPB.AddProperty("OnCheckedChanged", "chk" & sColumnName & "_CheckedChanged")
                    '    clsPB.AddAutoPostBack(True)
                    'End If
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:HyperLink>")
                Case "HtmlEditor"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:HtmlEditor ")
                    clsPB.AddID("html" & sColumnName)
                    clsPB.AddRunAtServer()
                    If sIsReadOnly = "Y" Then clsPB.AddProperty("ReadOnly", "true")
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    clsPB.AddProperty("EnableAlignments", "true")
                    clsPB.AddProperty("EnableChineseFont", "true")
                    clsPB.AddProperty("EnableColors", "true")
                    clsPB.AddProperty("EnableFont", "true")
                    clsPB.AddProperty("EnableFontSize", "true")
                    clsPB.AddProperty("EnableFormat", "true")
                    clsPB.AddProperty("EnableLinks", "true")
                    clsPB.AddProperty("EnableLists", "true")
                    clsPB.AddProperty("EnableSourceEdit", "true")

                    'If sIsRequired = "Y" Then
                    '    clsPB.AddShowRedStar(True)
                    '    clsPB.AddRequired(True)
                    '    clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    'End If
                    If sIsAutoPostBack = "Y" Then
                        clsPB.AddProperty("OnTextChanged", "html" & sColumnName & "_TextChanged")
                        clsPB.AddAutoPostBack(True)
                    End If
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:HtmlEditor>")

                Case "CheckBox"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:CheckBox ")
                    clsPB.AddID("chk" & sColumnName)
                    clsPB.AddRunAtServer()
                    If sIsReadOnly = "Y" Then clsPB.AddProperty("ReadOnly", "true")
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    'If sIsRequired = "Y" Then
                    '    clsPB.AddShowRedStar(True)
                    '    clsPB.AddRequired(True)
                    '    clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    'End If
                    If sIsAutoPostBack = "Y" Then
                        clsPB.AddProperty("OnCheckedChanged", "chk" & sColumnName & "_CheckedChanged")
                        clsPB.AddAutoPostBack(True)
                    End If
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:CheckBox>")
                Case "DropDownList"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:DropDownList ")
                    clsPB.AddID("cbo" & sColumnName)
                    clsPB.AddRunAtServer()
                    If sIsReadOnly = "Y" Then clsPB.AddProperty("ReadOnly", "true")
                    clsPB.AddEmptyText(sEmptyText)
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    If sIsRequired = "Y" Then
                        clsPB.AddShowRedStar(True)
                        clsPB.AddRequired(True)
                        clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    End If
                    If sIsAutoPostBack = "Y" Then
                        clsPB.AddProperty("OnSelectedIndexChanged", "cbo" & sColumnName & "_SelectedIndexChanged")
                        clsPB.AddAutoPostBack(True)
                    End If
                    clsPB.AddProperty("EnableEdit", "true")
                    clsPB.AddProperty("ForceSelection", "true")
                    clsPB.AddProperty("TypeAhead", "true")
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:DropDownList>")
                Case "TextBox"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:TextBox ")
                    clsPB.AddID("txt" & sColumnName)
                    clsPB.AddRunAtServer()
                    If sIsReadOnly = "Y" Then clsPB.AddProperty("ReadOnly", "true")
                    clsPB.AddProperty("VType", "All")
                    clsPB.AddEmptyText(sEmptyText)
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    If sIsRequired = "Y" Then
                        clsPB.AddShowRedStar(True)
                        clsPB.AddRequired(True)
                        clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    End If
                    If sIsAutoPostBack = "Y" Then
                        clsPB.AddProperty("OnTextChanged", "txt" & sColumnName & "_TextChanged")
                        clsPB.AddAutoPostBack(True)
                    End If
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:TextBox>")
                Case "DatePicker"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:DatePicker ")
                    clsPB.AddID("date" & sColumnName)
                    clsPB.AddRunAtServer()
                    If sIsReadOnly = "Y" Then clsPB.AddProperty("ReadOnly", "true")
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    clsPB.AddProperty("DateFormatString", sDataFormat)
                    If sIsRequired = "Y" Then
                        clsPB.AddShowRedStar(True)
                        clsPB.AddRequired(True)
                        clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    End If
                    If sIsAutoPostBack = "Y" Then
                        clsPB.AddProperty("EnableDateSelect", "true")
                        clsPB.AddProperty("OnDateSelect", "date" & sColumnName & "_DateSelect")
                        clsPB.AddAutoPostBack(True)
                    End If
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:DatePicker>")
                Case "TextArea"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:TextArea ")
                    clsPB.AddID("txt" & sColumnName)
                    clsPB.AddRunAtServer()
                    If sIsReadOnly = "Y" Then clsPB.AddProperty("ReadOnly", "true")
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    If sIsRequired = "Y" Then
                        clsPB.AddShowRedStar(True)
                        clsPB.AddRequired(True)
                        clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    End If
                    If sIsAutoPostBack = "Y" Then
                        clsPB.AddProperty("OnTextChanged", "txt" & sColumnName & "_TextChanged")
                        clsPB.AddAutoPostBack(True)
                    End If
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:TextArea>")
                Case "RadioButton"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:RadioButton ")
                    clsPB.AddID("radio" & sColumnName)
                    clsPB.AddRunAtServer()
                    If sIsReadOnly = "Y" Then clsPB.AddProperty("ReadOnly", "true")
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    'If sIsRequired = "Y" Then
                    '    clsPB.AddShowRedStar(True)
                    '    clsPB.AddRequired(True)
                    '    clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    'End If
                    If sIsAutoPostBack = "Y" Then
                        clsPB.AddProperty("OnCheckedChanged", "radio" & sColumnName & "_CheckedChanged")
                        clsPB.AddAutoPostBack(True)
                    End If
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:RadioButton>")
                Case "FileUpload"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:FileUpload ")
                    clsPB.AddID("file" & sColumnName)
                    clsPB.AddRunAtServer()
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    clsPB.AddProperty("ButtonOnly", "false")
                    clsPB.AddProperty("ButtonText", sCaption)
                    clsPB.AddProperty("ButtonIcon", "FineUI.Icon.Upload")
                    'If sIsRequired = "Y" Then
                    '    clsPB.AddShowRedStar(True)
                    '    clsPB.AddRequired(True)
                    '    clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    'End If
                    If sIsAutoPostBack = "Y" Then
                        clsPB.AddProperty("OnFileSelected", "file" & sColumnName & "_FileSelected")
                        clsPB.AddAutoPostBack(True)
                    End If
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:FileUpload>")
                Case "LinkButton"
                Case "HiddenField"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:HiddenField ")
                    clsPB.AddID("hidden" & sColumnName)
                    clsPB.AddRunAtServer()
                    If sIsReadOnly = "Y" Then clsPB.AddProperty("ReadOnly", "true")
                    clsPB.AddProperty("VType", "All")
                    clsPB.AddEmptyText(sEmptyText)
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    If sIsRequired = "Y" Then
                        clsPB.AddShowRedStar(True)
                        clsPB.AddRequired(True)
                        clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    End If
                    If sIsAutoPostBack = "Y" Then
                        clsPB.AddProperty("OnTextChanged", "hidden" & sColumnName & "_TextChanged")
                        clsPB.AddAutoPostBack(True)
                    End If
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:HiddenField>")
                Case "NumberBox"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:NumberBox ")
                    clsPB.AddID("number" & sColumnName)
                    clsPB.AddRunAtServer()
                    If sIsReadOnly = "Y" Then clsPB.AddProperty("ReadOnly", "true")
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    If sIsRequired = "Y" Then
                        clsPB.AddShowRedStar(True)
                        clsPB.AddRequired(True)
                        clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    End If
                    If sIsAutoPostBack = "Y" Then
                        clsPB.AddProperty("OnTextChanged", "number" & sColumnName & "_TextChanged")
                        clsPB.AddAutoPostBack(True)
                    End If
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:NumberBox>")
                Case "TimePicker"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:TimePicker ")
                    clsPB.AddID("time" & sColumnName)
                    clsPB.AddRunAtServer()
                    If sIsReadOnly = "Y" Then clsPB.AddProperty("ReadOnly", "true")
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    clsPB.AddProperty("TimeFormatString", sDataFormat)
                    If sIsRequired = "Y" Then
                        clsPB.AddShowRedStar(True)
                        clsPB.AddRequired(True)
                        clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    End If
                    If sIsAutoPostBack = "Y" Then
                        clsPB.AddProperty("EnableTimeSelect", "true")
                        clsPB.AddProperty("OnDateSelect", "time" & sColumnName & "_DateSelect")
                        clsPB.AddAutoPostBack(True)
                    End If
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:TimePicker>")
                Case "TriggerBox"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:TriggerBox ")
                    clsPB.AddID("trigger" & sColumnName)
                    clsPB.AddRunAtServer()
                    If sIsReadOnly = "Y" Then clsPB.AddProperty("ReadOnly", "true")
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    clsPB.AddProperty("EnableEdit", "true")
                    clsPB.AddProperty("ShowTrigger", "true")
                    clsPB.AddProperty("TriggerIcon", "FineUI.Icon.Search")
                    If sIsRequired = "Y" Then
                        clsPB.AddShowRedStar(True)
                        clsPB.AddRequired(True)
                        clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    End If
                    If sIsAutoPostBack = "Y" Then
                        clsPB.AddProperty("EnablePostBack", "true")
                        clsPB.AddProperty("OnTriggerClick", "trigger" & sColumnName & "_TriggerClick")
                        clsPB.AddAutoPostBack(True)
                    End If
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:TriggerBox>")
                Case "TwinTriggerBox"
                    clsPB = New clsPropertyBuilder
                    BE.Append("<ext:TwinTriggerBox ")
                    clsPB.AddID("twintrigger" & sColumnName)
                    clsPB.AddRunAtServer()
                    If sIsReadOnly = "Y" Then clsPB.AddProperty("ReadOnly", "true")
                    clsPB.AddLabel(sCaption)
                    If sIsVisible = "N" Then clsPB.AddHidden(True)
                    clsPB.AddProperty("EnableEdit", "true")
                    clsPB.AddProperty("ShowTrigger", "true")
                    clsPB.AddProperty("TriggerIcon", "FineUI.Icon.Search")
                    If sIsRequired = "Y" Then
                        clsPB.AddShowRedStar(True)
                        clsPB.AddRequired(True)
                        clsPB.AddRequiredMessage("The " & sCaption.ToLower & " should be specified.")
                    End If
                    If sIsAutoPostBack = "Y" Then
                        clsPB.AddProperty("EnablePostBack", "true")
                        clsPB.AddProperty("OnTriggerClick", "trigger" & sColumnName & "_TriggerClick")
                        clsPB.AddAutoPostBack(True)
                    End If
                    BE.Append(clsPB.Render)
                    BE.AppendLine("></ext:TwinTriggerBox>")
                Case "Accordion"
                Case "ContentPanel"
                Case "Form"
                Case "GroupPanel"
                Case "Panel"
                Case "SimpleForm"
                Case "Tree"
                Case "Window"
                Case "Grid"
                Case "RegionPanel"
                Case "TabStrip"
            End Select
            If Len(sLine) > 0 Then BE.AppendLine(sLine)
            BE.AppendLine("</Items>")
            BE.AppendLine("</ext:FormRow>")
            BE.AppendLine()
        Next
        BE.AppendLine()
    End Sub

End Class
